using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace SATF.DB
{
    public static class DBConvert
    {
        public static int ToInt32(DataRow dataRow, string columnName)
        {
            if (dataRow[columnName] != DBNull.Value)
            {
                return Convert.ToInt32(dataRow[columnName]);
            }
            else
            {
                return 0;
            }

        }

        public static UInt64 ToUInt64(DataRow dataRow, string columnName)
        {
            if (dataRow[columnName] != DBNull.Value)
            {
                return Convert.ToUInt64(dataRow[columnName]);
            }
            else
            {
                return 0;
            }

        }

        public static double ToDouble(DataRow dataRow, string columnName)
        {
            if (dataRow[columnName] != DBNull.Value)
            {
                return Convert.ToDouble(dataRow[columnName]);
            }
            else
            {
                return 0;
            }

        }

        public static int ToInt32(object input)
        {
            if (input == null)
            {
                return 0;
            }
            return Convert.ToInt32(input);
        }


        public static string ToString(DataRow dataRow, string columnName)
        {
            if (dataRow[columnName] != DBNull.Value)
            {
                return dataRow[columnName].ToString();
            }
            else
            {
                return null;
            }

        }

        public static bool ToBoolean(DataRow dataRow, string columnName)
        {
            if (dataRow[columnName] != DBNull.Value)
            {
                return Convert.ToBoolean(dataRow[columnName]);
            }
            else
            {
                return false;
            }
        }

        public static DateTime ToDateTime(DataRow dataRow, string columnName)
        {
            if (dataRow[columnName] != DBNull.Value)
            {
                return Convert.ToDateTime(dataRow[columnName]);
            }
            else
            {
                return DateTime.MinValue;
            }

        }
    }
}
